import React from 'react'
import store from '../../store/store'
import {incrementCount,decrementCount,waitDecrementCount} from '../../store/actions/countAction'
export default function Count() {
    const { count } = store.getState().count
    //增量处理
    const incrementHandle = () => {
        store.dispatch(incrementCount(1))
    }
    //减量处理
    const decrementHandle = () => {
        store.dispatch(decrementCount(1))
    }
    //如果是奇数在增
    const ifOddDecrementHandle = () => {
        if (count % 2 !== 0) {
            store.dispatch(incrementCount(1))
        }
    }
    //等会在增
    const waitDecrementHandle = () => {
            store.dispatch(waitDecrementCount(1))
    }
    return (
        <div>
            <h1>我是Count组件 我的值是{count}</h1>
            <div>
                <button onClick={incrementHandle}>累加</button>
                <button onClick={decrementHandle}>累减</button>
                <button onClick={ifOddDecrementHandle}>如果是奇数在加1</button>
                <button onClick={waitDecrementHandle}>等2s再加1</button>
            </div>
        </div>
    )
}
